package com.outdoor.model.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.outdoor.util.StringListConverter;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.List;

@Data
@EqualsAndHashCode(callSuper = true)
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName("users")
public class User extends BaseEntity {
    
    @TableId(type = IdType.AUTO)
    private Long id;
    private String username;
    private String name;
    private String bio;
    
    // 数据库中存储的是字符串
    @JsonIgnore
    private String interests;
    
    // 非数据库字段，用于与前端交互
    @TableField(exist = false)
    @JsonProperty("interests")
    private List<String> interestsList;
    
    // 数据库中存储的是字符串
    @JsonIgnore
    private String equipment;
    
    // 非数据库字段，用于与前端交互
    @TableField(exist = false)
    @JsonProperty("equipment")
    private List<String> equipmentList;
    
    private String wechatId;
    private Integer tripsCount;
    
    // 获取兴趣列表，用于与前端交互
    public List<String> getInterestsList() {
        if (interestsList == null && interests != null) {
            interestsList = StringListConverter.stringToList(interests);
        }
        return interestsList;
    }
    
    // 设置兴趣列表，同时更新字符串形式
    public void setInterestsList(List<String> interestsList) {
        this.interestsList = interestsList;
        this.interests = StringListConverter.listToString(interestsList);
    }
    
    // 获取装备列表，用于与前端交互
    public List<String> getEquipmentList() {
        if (equipmentList == null && equipment != null) {
            equipmentList = StringListConverter.stringToList(equipment);
        }
        return equipmentList;
    }
    
    // 设置装备列表，同时更新字符串形式
    public void setEquipmentList(List<String> equipmentList) {
        this.equipmentList = equipmentList;
        this.equipment = StringListConverter.listToString(equipmentList);
    }
}